Skip to content

allow wsh ai to attach directory listings to the chat#2469

Merged
sawka merged 2 commits intomainfrom
sawka/wsh-ai-dir
Oct 22, 2025
Merged

allow wsh ai to attach directory listings to the chat#2469
sawka merged 2 commits intomainfrom
sawka/wsh-ai-dir

Conversation

@sawka
Copy link
Member

@sawka sawka commented Oct 21, 2025

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2025

Walkthrough

Adds first-class directory support across the AI chat stack: a new util/fileutil.ReadDir that returns rich directory metadata and truncation info; backend changes to treat directories as uploadable content (cmd/wsh/cmd/wshcmd-ai.go) and to produce/parse AttachedDirectoryListing tags in the OpenAI conversion layer (pkg/aiusechat/openai/openai-convertmessage.go); tools_readdir.go now delegates to fileutil.ReadDir and removes its previous DirEntryOut type; system prompt updated to document AttachedDirectoryListing; frontend ai-utils.ts includes a directory fileType/icon case. Several files adjusted to use absolute paths and JSON-encode directory listings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive No pull request description was provided by the author. While the check is intended to be lenient and pass as long as the description is not off-topic, the complete absence of any description means there is no information available to assess whether it relates to the changeset or not. This creates an ambiguous situation where the criterion for passing (description related to changeset) cannot be verified either way.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "allow wsh ai to attach directory listings to the chat" is directly and accurately related to the main change in this changeset. The summary confirms that all changes across multiple files are focused on introducing directory attachment functionality to the AI chat system, including handling directory inputs, parsing directory listings, and extending system prompts to support attached directories. The title is specific, concise, and clearly communicates the primary feature being added without ambiguity or unnecessary detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sawka/wsh-ai-dir

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b132da and 23d5846.

📒 Files selected for processing (1)
  • pkg/aiusechat/usechat.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/aiusechat/usechat.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build for TestDriver.ai
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: unknown linters: 'unusedfunc,unusedparams', run 'golangci-lint help linters' to see the list of supported linters
The command is terminated due to an error: unknown linters: 'unusedfunc,unusedparams', run 'golangci-lint help linters' to see the list of supported linters


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
pkg/util/fileutil/readdir.go (2)

60-79: Consider the symlink resolution cap behavior.

The 1000-symlink cap is a reasonable performance safeguard. However, note that after 1000 symlinks, the function stops resolving symlink targets and uses entry.IsDir() instead, which may return incorrect values for symlinks to directories. This creates potentially inconsistent sorting behavior within the same listing if you have more than 1000 symlinks.

This is likely acceptable for the use case, but consider documenting this behavior if it's intentional.


96-120: Consider logging errors when entry.Info() fails.

The function silently skips entries when entry.Info() fails (lines 99-101). While this prevents the entire operation from failing due to a single problematic entry, it could be confusing if entries are missing due to permission issues or other errors.

Consider logging these errors in development mode to aid debugging.

pkg/aiusechat/usechat.go (1)

70-72: Add punctuation for consistency.

Line 71 is missing a period at the end, unlike Line 70. Consider adding one for consistency with the surrounding text style.

Apply this diff:

-	"User-attached directories use the tag <AttachedDirectoryListing_xxxxxxxx directory_name="...">JSON DirInfo</AttachedDirectoryListing_xxxxxxxx>",
+	"User-attached directories use the tag <AttachedDirectoryListing_xxxxxxxx directory_name=\"...\">JSON DirInfo</AttachedDirectoryListing_xxxxxxxx>.",
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 271c355 and 8b132da.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • cmd/wsh/cmd/wshcmd-ai.go (3 hunks)
  • frontend/app/aipanel/ai-utils.ts (12 hunks)
  • pkg/aiusechat/openai/openai-convertmessage.go (2 hunks)
  • pkg/aiusechat/tools_readdir.go (2 hunks)
  • pkg/aiusechat/usechat.go (1 hunks)
  • pkg/util/fileutil/readdir.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
pkg/aiusechat/openai/openai-convertmessage.go (2)
pkg/aiusechat/openai/openai-backend.go (1)
  • OpenAIMessageContent (66-78)
pkg/aiusechat/uctypes/usechat-types.go (2)
  • UIMessagePart (35-68)
  • UIMessageDataUserFile (70-75)
cmd/wsh/cmd/wshcmd-ai.go (1)
pkg/util/fileutil/readdir.go (1)
  • ReadDir (38-137)
pkg/util/fileutil/readdir.go (1)
pkg/util/utilfn/utilfn.go (1)
  • FormatRelativeTime (1114-1154)
pkg/aiusechat/tools_readdir.go (1)
pkg/util/fileutil/readdir.go (1)
  • ReadDir (38-137)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (13)
frontend/app/aipanel/ai-utils.ts (1)

78-80: LGTM! Directory icon handling added.

The directory type check correctly returns the folder icon, consistent with the new directory attachment feature.

pkg/util/fileutil/readdir.go (5)

18-36: LGTM! Well-structured type definitions.

The types are appropriately designed for JSON serialization with proper use of omitempty for optional fields.


38-51: LGTM! Path validation is correct.

The function properly expands the home directory, validates the path exists, and ensures it's a directory before proceeding.


81-88: LGTM! Sorting logic is correct.

Directories are sorted first, then entries are sorted alphabetically. The use of the cached isDirMap avoids redundant lookups.


90-94: LGTM! Truncation logic is correct.

The function properly preserves the total entry count before truncation and sets the truncated flag.


122-136: LGTM! Result construction is correct.

The function properly constructs the result and handles the root directory edge case where filepath.Dir would return the same path.

pkg/aiusechat/openai/openai-convertmessage.go (3)

370-393: LGTM! Directory conversion logic is correct.

The directory handling properly mirrors the text file conversion logic with appropriate defaults and encoding.


396-396: LGTM! Error message updated correctly.

The error message now accurately reflects support for directories.


533-551: LGTM! Directory listing UI conversion is correct.

The directory tag parsing properly mirrors the text file handling and correctly creates a data-userfile part with the directory mime type.

cmd/wsh/cmd/wshcmd-ai.go (3)

112-115: LGTM! Absolute path logic correctly placed.

Getting the absolute path before the directory check is appropriate since both files and directories need it.


117-136: LGTM! Directory handling is correct.

The directory reading logic properly uses fileutil.ReadDir and marshals the result to JSON. The hard-coded maxEntries of 500 matches the default in tools_readdir.go.

One observation: Both files and directories now use absolute paths as fileName (lines 127, 134), which provides full context but may be verbose in the UI. This appears intentional and consistent.


139-148: LGTM! MIME type logic correctly handles directories.

The updated condition properly prevents directories from being coerced to text/plain, and the binary content check appropriately skips directories.

pkg/aiusechat/tools_readdir.go (1)

53-82: LGTM! Refactoring correctly delegates to fileutil.ReadDir.

The function properly uses the centralized directory reading utility and constructs an appropriate map-based response with helpful truncation messaging.

@sawka sawka merged commit edacd65 into main Oct 22, 2025
8 checks passed
@sawka sawka deleted the sawka/wsh-ai-dir branch October 22, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant